package exam.db.dao;

import java.util.List;

import exam.db.entity.TUserEntity;
import exam.db.entity.name.TUserEntityNames;
import exam.driver.jdbc.StatementSql;
import exam.driver.jdbc.WhereComplex;

/**
 * <p>TUserDao</p>
 * <p>Thực hiện các truy vấn cho TUserEntity</p>
 * 
 * @author PHONTN
 * @version 17/4/2012
 */

public class TUserDao extends AbstractDao<TUserEntity> {
	/**
	 * Constructor
	 */
	public TUserDao() {
		super(TUserEntity.class);
	}
	/**
	 * selectAll
	 * @return
	 */
	public List<TUserEntity> selectAll() {
		return super.selectAll(
				TUserEntityNames.class,
				new StatementSql()
					.select()
					.from(TUserEntityNames.TABLE_NAME)
					.toString()
				);
	}
	/**
	 * selectByPk
	 * @param pk
	 * @return
	 */
	public TUserEntity selectByPk(Integer pk) {
		return super.selectByPk(
				TUserEntityNames.class,
				new StatementSql()
					.select()
					.from(TUserEntityNames.TABLE_NAME)
					.where(
						new WhereComplex()
							.eq(TUserEntityNames.USER_ID, pk))
					.toString());
	}
	/**
	 * deleteByPk
	 * @param arrayPk
	 * @return
	 */
	public List<Integer> deleteByPk(int[] arrayPk) {
		return super.deleteByPk(
				new StatementSql()
					.delete()
					.from(TUserEntityNames.TABLE_NAME)
					.where(
						new WhereComplex()
							.eq(TUserEntityNames.USER_ID))
					.toString(), arrayPk);
	}
	/**
	 * insertByFile
	 * @param user
	 * @return
	 */
	public int insertByFile(TUserEntity user) {
		String sqlFile = "INSERT INTO	" +
				"T_USER (USERNAME, PASSWORD, FULLNAME, BIRTHDAY, GENDER, ADDRESS, ROLE, CREATE_DATE, UPDATE_DATE)" +
				"VALUES(?,?,?,?,?,?,?,?,?)";
		return super.insertBySqlFile(user, sqlFile);
	}
	/**
	 * updateByFile:TUserDao
	 * @param params
	 * @return
	 */
	public int updateByFile(List<Object> params) {
		String sqlFile = "src/exam/db/dao/sql/TUserEntity_update.sql";
		return super.updateBySqlFile(sqlFile, params);
	}
}
